home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk1 / files / gadget.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  6KB  |  211 lines

  1.  
  2. /*
  3.  *  GADGET.C
  4.  *
  5.  *  (c)Copyright 1987 Matthew Dillon, All Rights Reserved.
  6.  *
  7.  */
  8.  
  9. #include "files.h"
  10.  
  11. #define NI 0
  12.  
  13. static BORDER  Bdr[10];
  14.  
  15. static ITEXT   BText[] = {
  16.     { 3,0,JAM2,1,0,NULL,(ubyte *)"info"},
  17.     { 3,0,JAM2,1,0,NULL,(ubyte *)"del" },
  18.     { 3,0,JAM2,1,0,NULL,(ubyte *)"undo"},
  19.     { 3,0,JAM2,1,0,NULL,(ubyte *)"all" }
  20. };
  21.  
  22. static ITEXT   SText[] = {
  23.     { 3,0,JAM2,NI,-2,NULL,(ubyte *)"Volume:  " },
  24.     { 3,0,JAM2,NI,-2,NULL,(ubyte *)"Pattern: " },
  25.     { 3,0,JAM2,NI,-2,NULL,(ubyte *)"Comment: " }
  26. };
  27.  
  28. ubyte Buf1_vol[128]; ubyte Buf2_vol[128];
  29. ubyte Buf1_pat[128]; ubyte Buf2_pat[128];
  30. ubyte Buf1_com[128]; ubyte Buf2_com[128];
  31.  
  32. STRINGINFO  Si_vol = { Buf1_vol,Buf2_vol,0,sizeof(Buf1_vol),0,0,0,0,0,0 };
  33. STRINGINFO  Si_pat = { Buf1_pat,Buf2_pat,0,sizeof(Buf2_pat),0,0,0,0,0,0 };
  34. STRINGINFO  Si_com = { Buf1_com,Buf2_com,0,sizeof(Buf2_com),0,0,0,0,0,0 };
  35.  
  36. GADGET    Gad_vol = { NULL    ,  NI,    0, NI, NI, GADGHCOMP|GRELWIDTH,GADGIMMEDIATE|RELVERIFY,STRGADGET,NI,NULL,&SText[0],NULL,(APTR)&Si_vol };
  37. GADGET    Gad_pat = { &Gad_vol    ,  NI,    1, NI, NI, GADGHCOMP|GRELWIDTH,GADGIMMEDIATE|RELVERIFY,STRGADGET,NI,NULL,&SText[1],NULL,(APTR)&Si_pat };
  38. GADGET    Gad_com = { &Gad_pat    ,  NI,    2, NI, NI, GADGHCOMP|GRELWIDTH,GADGIMMEDIATE|RELVERIFY,STRGADGET,NI,NULL,&SText[2],NULL,(APTR)&Si_com };
  39.  
  40. GADGET    Gad_info= { &Gad_com    ,  5 ,-15, NI, NI, GADGHCOMP|GRELBOTTOM,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,NI,NULL,&BText[0] };
  41. GADGET    Gad_del = { &Gad_info    ,  50,-15, NI, NI, GADGHCOMP|GRELBOTTOM,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,NI,NULL,&BText[1] };
  42. GADGET    Gad_undo= { &Gad_del    ,-110,-15, NI, NI,GADGHCOMP|GRELRIGHT|GRELBOTTOM,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,NI,NULL,&BText[2] };
  43. GADGET    Gad_all = { &Gad_undo    , -50,-15, NI, NI, GADGHCOMP|GRELRIGHT|GRELBOTTOM,GADGIMMEDIATE|RELVERIFY,BOOLGADGET,NI,NULL,&BText[3] };
  44.  
  45. GADGET    *FirstGadget = &Gad_all;
  46.  
  47. GADGET    Gad_box = { NULL    ,  NI, NI, NI, NI, GADGHNONE|GRELWIDTH|GRELHEIGHT,GADGIMMEDIATE|RELVERIFY|FOLLOWMOUSE,BOOLGADGET,NULL,NULL,NULL };
  48.  
  49. PROPINFO Prop_slid = { AUTOKNOB|FREEVERT, 0, 0, 0x30, 0x30 };
  50. IMAGE     Imag_slid = { 0,0,2,1,1,NULL,1,0,NULL };
  51.  
  52. GADGET     Gad_slid  = { NULL,  -20, 12, 20, -30, GADGHCOMP|GRELHEIGHT|GRELRIGHT,GADGIMMEDIATE|RELVERIFY|RIGHTBORDER|FOLLOWMOUSE,PROPGADGET,(APTR)&Imag_slid,NULL,NULL,0,(APTR)&Prop_slid };
  53.  
  54. initslider(nw)
  55. NW *nw;
  56. {
  57.     nw->FirstGadget = &Gad_slid;
  58. }
  59.  
  60. initstructs()
  61. {
  62.     register short i;
  63.     register GADGET *gad;
  64.  
  65.     for (i = 0; i < sizeof(Bdr)/sizeof(Bdr[0]); ++i) {
  66.     register BORDER *b = &Bdr[i];
  67.     register short    *xy= malloc(5 * 2 * sizeof(short));
  68.     /*b->LeftEdge = b->TopEdge = -2;*/
  69.     b->FrontPen = 1;
  70.     b->DrawMode = JAM2;
  71.     b->Count = 5;
  72.     b->XY = xy;
  73.     bzero(xy, 5 * 2 * sizeof(short));
  74.     xy[2] = i * Win->RPort->TxWidth + 4;
  75.     xy[4] = xy[2];
  76.     xy[5] = Win->RPort->TxHeight + 2;
  77.     xy[7] = Win->RPort->TxHeight + 2;
  78.     }
  79.     for (i = 0; i < sizeof(SText)/sizeof(SText[0]); ++i) {
  80.     register ITEXT *it = &SText[i];
  81.     it->LeftEdge = -strlen(it->IText) * Win->RPort->TxWidth + 2;
  82.     it->TopEdge += 2;
  83.     }
  84.     for (i = 0; i < sizeof(BText)/sizeof(BText[0]); ++i) {
  85.     register ITEXT *it = &BText[i];
  86.     it->LeftEdge+= 2;
  87.     it->TopEdge += 2;
  88.     }
  89.     for (gad = FirstGadget; gad; gad = gad->NextGadget) {
  90.     register ubyte *str = gad->GadgetText->IText;
  91.     gad->Height = Win->RPort->TxHeight + 3;
  92.     gad->Width  = strlen(str) * Win->RPort->TxWidth + 5;
  93.     if (gad->GadgetType == STRGADGET) {
  94.         gad->LeftEdge = Win->BorderLeft + strlen(str) * Win->RPort->TxWidth + 2;
  95.         gad->Width      = -gad->LeftEdge - Win->BorderRight;
  96.         gad->TopEdge = gad->TopEdge * (Win->RPort->TxHeight + 2) + Win->BorderTop;
  97.         gad->GadgetText->LeftEdge = -strlen(str) * Win->RPort->TxWidth;
  98.     } else {
  99.         gad->GadgetRender = (APTR)&Bdr[strlen(str)];
  100.     }
  101.     }
  102.     Gad_box.LeftEdge= Win->BorderLeft;
  103.     Gad_box.TopEdge = Gad_com.TopEdge + Win->RPort->TxHeight + 2;
  104.     Gad_box.Width   = -Gad_box.LeftEdge - Win->BorderRight;
  105.     Gad_box.Height  = -Gad_box.TopEdge    + Gad_undo.TopEdge - 2;
  106. }
  107.  
  108. addgadgets()
  109. {
  110.     register GADGET *gad, *ngad;
  111.     int i = 0;
  112.  
  113.     initstructs(Win);
  114.     for (gad = FirstGadget; gad; gad = ngad) {
  115.     ngad = gad->NextGadget;
  116.     AddGadget(Win, gad, i);
  117.     ++i;
  118.     }
  119.     AddGadget(Win, &Gad_box, i);
  120.     RefreshGList(FirstGadget, Win, NULL, -1);
  121. }
  122.  
  123. remgadgets()
  124. {
  125.  
  126. }
  127.  
  128. fixgadgets()
  129. {
  130.  
  131. }
  132.  
  133. getgadget(im, sel, str)
  134. IMESS *im;
  135. short *sel;
  136. ubyte **str;
  137. {
  138.     GADGET *gad = (GADGET *)im->IAddress;
  139.  
  140.     *sel = gad->Flags & SELECTED;
  141.  
  142.     if (gad == &Gad_info) return(GAD_INFO);
  143.     if (gad == &Gad_del)  return(GAD_DEL);
  144.     if (gad == &Gad_undo) return(GAD_UNDO);
  145.     if (gad == &Gad_all)  return(GAD_ALL);
  146.     if (gad == &Gad_slid) return(GAD_SLIDER);
  147.     if (gad == &Gad_box)  return(GAD_BIGBOX);
  148.  
  149.     if (gad == &Gad_vol || gad == &Gad_pat || gad == &Gad_com) {
  150.     *str = ((STRINGINFO *)gad->SpecialInfo)->Buffer;
  151.     if (gad == &Gad_vol) return(GAD_VOLUME);
  152.     if (gad == &Gad_pat) return(GAD_PATTERN);
  153.     if (gad == &Gad_com) return(GAD_COMMENT);
  154.     }
  155.     return(0);
  156. }
  157.  
  158. bigboxbounds(xs,xe,ys,ye)
  159. short *xs,*xe,*ys,*ye;
  160. {
  161.     *xs = Gad_box.LeftEdge;
  162.     *xe = *xs + Gad_box.Width + Win->Width;
  163.     *ys = Gad_box.TopEdge;
  164.     *ye = *ys + Gad_box.Height+ Win->Height;
  165.     if (*xe <= *xs)
  166.     *xe = *xs + 1;
  167.     if (*ye <= *ys)
  168.     *ye = *ys + 1;
  169. }
  170.  
  171. getsliderpos(pot, full)
  172. short *pot, *full;
  173. {
  174.     *pot = Prop_slid.VertPot;
  175.     *full= Prop_slid.VertBody;
  176. }
  177.  
  178. getboxpos(im)
  179. IMESS *im;
  180. {
  181.     return(im->MouseY - Gad_box.TopEdge);
  182. }
  183.  
  184. setslider(pos, fatness)
  185. {
  186.     NewModifyProp(&Gad_slid, Win, NULL, AUTOKNOB|FREEVERT,0,pos,0,fatness,1);
  187. }
  188.  
  189. setcomment(str)
  190. char *str;
  191. {
  192.     strcpy(Buf1_com, str);
  193.     RefreshGList(&Gad_com, Win, NULL, 1);
  194. }
  195.  
  196. activate_vol()
  197. {
  198.     ActivateGadget(&Gad_vol, Win, NULL);
  199. }
  200.  
  201. activate_pat()
  202. {
  203.     ActivateGadget(&Gad_pat, Win, NULL);
  204. }
  205.  
  206. activate_com()
  207. {
  208.     ActivateGadget(&Gad_com, Win, NULL);
  209. }
  210.  
  211.